﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class ForgetPwd_ForgetMessage_ : System.Web.UI.Page
{
    WebUtility util = new WebUtility();
    BLL.ReadParamtes read = new ReadParamtes();
    BLL.SendSMS sendSms = new SendSMS();
    BLL.ConsultationCardPwdSelect bllCardInfo = new ConsultationCardPwdSelect();
 
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 获取用户密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImgBtn_Query_Click(object sender, ImageClickEventArgs e)
    {
        string mobile = WebUtility.replaceStr(this.MobileNO.Text.Trim());
        string validateCode = WebUtility.replaceStr(this.Txt_ValidateCode.Text.Trim());

        //验证验证码是否过期
        bool isRequestTimeOut = bllCardInfo.IsRequestTimedOut(mobile, validateCode);
        if (isRequestTimeOut == false)
        {
            this.Txt_ValidateCode.Text = "";
            util.AlertMsg("对不起，您所输入的验证码已过期！请重新申请。");
        }
        else
        {
            bool isSame =bllCardInfo.IsSameToVerifyCodeAndMobileNO(mobile, validateCode);
            if (isSame == false)
            {
                this.Txt_ValidateCode.Text = "";
                util.AlertMsg("对不起，您所输入的验证码错误！请重新申请。");
            }
            //验证码未过期并且正确
            else
            {
                BLL.UserBean bean = new UserBean();
                string accountPwd = bean.getUserAccountPwd(mobile);
                if (!string.IsNullOrEmpty(accountPwd))
                {
                    string smsTemplate = read.getParamValue("findRegUserAccountPwd");
                    string message = WebUtility.GenreateFindRegUserAccountPwdMsg(mobile, accountPwd, smsTemplate);
                    sendSms.SendMsg(message,mobile,"1");
                    util.AlertMsg("将有一条短信发送到你的手机上，请注意查收!");
                }
                else 
                {
                    util.AlertMsg("没有该用户的注册记录，请检查填写信息");
                }
            }
        }
        //---------------------------------------
    }
}
